package com.project.im.web.controller;

import com.project.im.app.dto.WebUserLoginDTO;
import com.project.im.app.dto.WebUserRegisterDTO;
import com.project.im.app.vo.ResponseVO;
import com.project.im.common.annotation.Log;
import com.project.im.web.service.AuthWebService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "认证管理")
@RestController
@RequestMapping("/web/v1/auth")
@RequiredArgsConstructor
public class AuthWebController {

    private final AuthWebService authWebService;

    @Log("认证管理-登录")
    @Operation(summary = "登录")
    @PostMapping("/login")
    public ResponseVO<String> login(@Valid @RequestBody WebUserLoginDTO userLoginDTO) {
        return ResponseVO.success(authWebService.login(userLoginDTO));
    }

    @Log("认证管理-注册")
    @Operation(summary = "注册")
    @PostMapping("/register")
    public ResponseVO<?> register(@Valid @RequestBody WebUserRegisterDTO userRegisterDTO) {
        authWebService.register(userRegisterDTO);
        return ResponseVO.success();
    }

}
